package com.abyss.source;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * 基于本地集合的非并行Source
 */
public class BasicSourceWithOutParallelDemo {
    /*
    1. 获得env执行环境
    2. 准备source
    3. 数据处理
    4. 数据的输出
     */
    public static void main(String[] args) throws Exception {
        // 1. 获得流处理的Env对象，是StreamExecutionEnvironment
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 2.1 获得元素列表来获取Source
        DataStreamSource<String> source1 = env.fromElements(
                "haha",
                "hehe", "heihei"
        );

        // 2.2 通过集合来获取Source
        DataStreamSource<String> source2 = env
                .fromCollection(Arrays.asList("hadoop", "spark", "flink"));

        // 3. 数据处理省略

        // 4. sink
        source1.print();
        source2.print();

        // 5. 提交任务
        env.execute();
    }
}